< previous page page_69 next page >

Page 69
Puzzle 16
Serially Speaking
One of the most common questions I receive relates to retrieving a disk volume serial number. This can be done using the GetVolumeInformation function, which is defined in the Win32 SDK documentation as follows:
BOOL GetVolumeInformation(
  LPCTSTR lpRootPathName,           // address of root directory of the
                                    // file system
  LPTSTR lpVolumeNameBuffer,        // address of name of the volume
  DWORD nVolumeNameSize,            // length of lpVolumeNameBuffer
  LPDWORD lpVolumeSerialNumber,     // address of volume serial number
  LPDWORD lpMaximumComponentLength, // address of system's maximum
                                    // filename length
  LPDWORD lpFileSystemFlags,        // address of file system flags
  LPTSTR lpFileSystemNameBuffer,    // address of name of file system
  DWORD nFileSystemNameSize         // length of lpFileSystemNameBuffer
);
Like many API functions, these parameters are almost self-explanatory. The lpRootPathName parameter should contain the root directory of the volume for which you want to obtain information. The following sample program has a drive control that allows you to select a drive to check. It then displays the volume name, file system name, maximum file-name length, and serial number in a list box.
' Volume Information
' Copyright © 1998 by Desaware Inc. All Rights Reserved

Option Explicit

Private Declare Function GetVolumeInformation Lib "kernel32" _
Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, _
ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, _
ByVal lpVolumeSerialNumber As Long, ByVal lpMaximumComponentLength _
As Long, ByVal lpFileSystemFlags As Long, ByVal _
lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long

 
< previous page page_69 next page >